home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13012 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.8 KB  |  71 lines

  1. Newsgroups: comp.lang.c++,comp.lang.java
  2. Path: netcom.com!milod
  3. From: milod@netcom.com (John DiCamillo)
  4. Subject: Re: Java: What's the Big Deal?
  5. Message-ID: <milodDoouru.Dz8@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. References: <milodDoF9JF.K32@netcom.com> <1996Mar20.154600.12011@amc.com> <4iuenj$ng2@decaxp.HARVARD.EDU>
  8. Date: Fri, 22 Mar 1996 21:38:18 GMT
  9. Sender: milod@netcom16.netcom.com
  10.  
  11. robison@mito.harvard.edu (Keith Robison) writes:
  12. >Curtis Green (curtis@amc.com) wrote:
  13. >: John DiCamillo (milod@netcom.com) wrote:
  14. >: : pete@borland.com (Pete Becker) writes:
  15.  
  16. >: : >>2) No header files => faster compilation
  17. >: : 
  18. >: : >Nonsense. Header files are simply text that gets included where you want it. If 
  19. >: : >you write the same code without header files it will not magically compile 
  20. >: : >faster.
  21. >: : 
  22. >: : It's not nonsense.  Cascaded #includes result in such a
  23. >: : drastic inflation of the source text that it makes a measurable
  24. >: : increase in compilation time.
  25. >: If you surround your header file with #ifndef .. #endif you should be able
  26. >: to eliminate your cascaded #include problem
  27. >: foo.h
  28. >: #ifndef FOO_H
  29. >: #define FOO_H
  30. >: ...
  31. >: #endif
  32.  
  33. >I think what the author was referring to was not multiply-including
  34. >a particular header file (which is generally a compile-time error),
  35. >but the fact that each header includes other headers which include
  36. >other headers (etc).  This can indeed take a long time with a large
  37. >header file collection, even if properly defended as above.
  38.  
  39. Correct, although if you know the guard flags, you can say
  40.  
  41. #ifndef FOO_H
  42. #include foo.h
  43. #endif
  44.  
  45. at each point where you might want to include foo.h.  This way,
  46. if you've already seen the file, it won't be re-expanded by the
  47. preprocessor.  We used this technique on one large project with
  48. BC4.5, and it saved us some time.
  49.  
  50. >What is far more evil is that your namespace depends on this
  51. >rat's nest of includes, and that the actual pattern of includes
  52. >depends on the includes.  This is one feature I really like about
  53. >Java -- you are required to explicitly set up your namespace, and
  54. >therefore the namespace for a given compilation unit can be determined
  55. >by the text in that source file; no identifiers sneaking in because
  56. >they were included 10 levels back.  
  57.  
  58. The real point is that since the preprocessor can effectively
  59. modify the contents of a header file as it is included, the
  60. compiler must continually re-parse the same header file for
  61. each source file.  In Java, once a module has been compiled
  62. once, the compiler is done -- from then on it can just re-use
  63. the .class file for subsequent imports.
  64.  
  65. -- 
  66.     ciao,
  67.     milo
  68. ================================================================
  69.     John DiCamillo                         Fiery the Angels Fell 
  70.     milod@netcom.com       Deep thunder rode around their shores
  71.